package gameEngine.agents.choosingStrategy;

import java.util.ArrayList;
import org.apache.log4j.Logger;
import gameEngine.agents.teamMateModel.AgentMock;
import gameEngine.agents.teamMateModel.TeamMateModel;
/**
 * use round robin to select next player
 * @author alon
 *
 */
public class RoundRobinStrategy implements ChoosingStrategy {

	Logger log = Logger.getLogger(this.getClass());
	int currentId;
	ArrayList<AgentMock> agents;
	
	/**
	 * saves last passed agent and pass to the next (sort by id)
	 */
	public int chooseNextPlayer(TeamMateModel teamMateModel) {
		if(agents==null){
			agents=new ArrayList<AgentMock>();
			agents.addAll(teamMateModel.getTeamMates());
		}
		int agent=agents.get(currentId).getId();
		if(currentId<agents.size()-1){
			currentId++;
		}else{
			currentId=0;
		}
		log.debug("selected agent is agent "+agent);
		return agent;
	}

	public RoundRobinStrategy clone(){
		RoundRobinStrategy copy=new RoundRobinStrategy();
		copy.agents=null;
		copy.currentId=0;
		return copy;
	}
}
